/* Copyright 2017, 2018, Gabriel Czernikier
 *
 * This file is part of Notehaus.
 * Notehaus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * Notehaus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Notehaus.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef __NOTEHAUS_LGWSEQ_T
#define __NOTEHAUS_LGWSEQ_T
#include <iconv.h>
#include <wchar.h>
#include <stddef.h>
#include <stdlib.h>
#include "types.h"

struct lgwseq_st {
  wchar_t *data;
  size_t length;
};
typedef struct lgwseq_st lgwseq_t;

/* s: The address of an expectedly uninitialized pointer. To be used as out parameter.
 * lg: The length
 * from: The original wide string, delimited not by NULL but by an up boundary at (from+lg) interpreted as "the last addressable position +1"
 */
lgwseq_t *for_lgwseq(lgwseq_t **s, size_t lg, const wchar_t *from);

/* Packs a lengthed wide sequence a.k.a. lgwseq_t, that consists of a wide string delimited not by a NULL character but by an adjunct length attribute.
 * The string is packed in a form referred to as MUTF-8, that can be described as a CESU-8 encoding with added transformations to support
 * surrogate-like (more precisely "overlongly encoded") NULL codepoint and non-surrogated (straightfowardly represented) NULL-terminating character.
 * The original length is packed, behind the packed string, using uleb128, a variable length encoding for numbers (with the restriction that as a number it can never extend beyond 32-bit).
 * returns the string+length packed data size.
 * Params:
 * for_pack: The lengthed wide sequence to be packed.
 * packed_out: The address of an expectedly uninitialized pointer where to store the packed data (i.e. an out param).
 */
size_t pack_string_data(const lgwseq_t *for_pack, void **packed_out);

int lgwseq_t_compar(const lgwseq_t *lgwseq1, const lgwseq_t *lgwseq2);

lgwseq_t *lgwseq_concat(int n_str, ...);
#endif
